function fig = fm_license(varargin)
% FM_LICENSE create GUI for the GNU-GPL
%
% HDL = FM_LICENSE()
%
%Author:    Federico Milano
%Date:      11-Nov-2002
%Update:    10-Feb-2003
%Version:   1.0.2
%
%E-mail:    Federico.Milano@uclm.es
%Web-site:  http://www.uclm.es/area/gsee/Web/Federico
%
% Copyright (C) 2002-2013 Federico Milano

global Settings Fig Path Theme

if nargin

  if ~exist('Fig'), Fig.license = 0, end
  if ~Fig.license
    Fig.license = findobj(get(0,'Children'),'FileName','fm_license');
  end

  switch varargin{1}

   case 'keyesc'

    tasto = get(gcf,'CurrentCharacter');
    if (double(tasto) == 13 || double(tasto) == 27), close(gcf); end

   case 'buttondown'

    pos = get(Fig.license,'CurrentPoint');
    if pos(1) > 0.05 && pos(2) > 0.05 && pos(1) < 0.95 && pos(2) < 0.25
      if strcmp(get(Fig.license,'SelectionType'),'open'),
	web('http://www.fsf.org/');
      end
    end

   case 'buttonmotion'

    if Settings.hostver >= 7.01
      pointer = 'hand';
    else
      pointer = 'crosshair';
    end

    pos = get(Fig.license,'CurrentPoint');
    if pos(1) > 0.05 && pos(2) > 0.05 && pos(1) < 0.95 && pos(2) < 0.25
      set(Fig.license,'Pointer',pointer);
    else
      set(Fig.license,'Pointer','arrow');
    end

  end
  return
end

if Fig.license > 0
  figure(Fig.license)
  return
end

helpstr = help('gnulicense');
retidx = findstr(helpstr,char(10));
retidx = [0,retidx,length(helpstr)+1];
testo = cell(length(retidx)-1,1);
for i = 1:length(retidx)-1
  testo{i} = helpstr([retidx(i)+1:retidx(i+1)-1]);
end

h0 = figure('Color',Theme.color01, ...
            'Units', 'normalized', ...
            'Colormap',[], ...
            'CreateFcn','Fig.license = gcf;', ...
            'DeleteFcn','Fig.license = 0;', ...
            'FileName', 'fm_license', ...
            'KeyPressFcn','fm_license keyesc', ...
            'MenuBar','none', ...
            'Name','GNU General Public License', ...
            'NumberTitle','off', ...
            'PaperPosition',[18 180 576 432], ...
            'PaperUnits','points', ...
            'Position',sizefig(1.2*0.5,1.4*0.357), ...
            'Resize','on', ...
            'ToolBar','none', ...
            'WindowButtonDownFcn','fm_license buttondown', ...
            'WindowButtonMotionFcn','fm_license buttonmotion');
fm_set colormap

% Menu File
h1 = uimenu('Parent',h0, ...
	    'Label','File', ...
	    'Tag','MenuFile');
h2 = uimenu('Parent',h1, ...
	    'Callback','web(''http://www.fsf.org/'');', ...
	    'Label','GNU Web Site', ...
	    'Tag','NetSett', ...
	    'Accelerator','w');
h2 = uimenu('Parent',h1, ...
	    'Callback','close(gcf)', ...
	    'Label','Exit', ...
	    'Tag','NetSett', ...
	    'Accelerator','x', ...
	    'Separator', 'on');

h1 = axes('Parent',h0, ...
          'Box','on', ...
          'CameraUpVector',[0 1 0], ...
          'CameraUpVectorMode','manual', ...
          'Color',Theme.color04, ...
          'ColorOrder',Settings.color, ...
          'HitTest','off', ...
          'Layer','top', ...
          'Position',[0.05, 0.05, 0.9, 0.2], ...
          'Tag','Axes1', ...
          'XColor',Theme.color05, ...
          'XLim',[0.5 973.5], ...
          'XLimMode','manual', ...
          'XTickLabelMode','manual', ...
          'XTickMode','manual', ...
          'XTick',[], ...
          'YColor',Theme.color05, ...
          'YDir','reverse', ...
          'YLim',[0.5 688.5], ...
          'YLimMode','manual', ...
          'YTickLabelMode','manual', ...
          'YTickMode','manual', ...
          'YTick',[], ...
          'ZColor',[0 0 0]);
[a,map] = imread([Path.images,'misc_gnu.bmp'],'bmp');
h2 = image('Parent',h1, ...
           'CData', a, ...
           'Tag','Axes1Image1', ...
           'XData',[1 973], ...
           'YData',[1 688]);
colormap(map)
h1 = uicontrol('Parent',h0, ...
               'Units', 'normalized', ...
               'BackgroundColor',Theme.color11, ...
               'Enable','inactive', ...
               'ForegroundColor',Theme.color05, ...
               'HorizontalAlignment','left', ...
               'Min', 0, ...
               'Max', 2, ...
               'Position',[0.05, 0.3, 0.9, 0.65], ...
               'String',testo, ...
               'Style','listbox', ...
               'Value',[], ...
               'Tag','Listbox1');

if isunix, set(h1,'Enable','on'), end

% h1 = uicontrol('Parent',h0, ...
%                'CData', fm_mat('ok'), ...
%                'Units', 'normalized', ...
%                'BackgroundColor',Theme.color03, ...
%                'Callback','close(gcf)', ...
%                'ForegroundColor',Theme.color09, ...
%                'Position',[0.25*0.5690, 0.1, 0.3*0.5690, 0.095], ...
%                'String','', ...
%                'Tag','Pushbutton1');

if nargout > 0, fig = h0; end